<?php

namespace Sinofaneliu\LaravelStart\Exceptions;

use Exception;

class ApiReturn extends Exception
{
    
    public $type;
    public $message;
    public $data;
    public $code;
    public $show_type;

    function __construct($type = 'SUCCESS', $message = '', $data = [], $code = '', $show_type = 0)
    {
        $this->type = $type;
        $this->message = $message;
        $this->data = $data;
        $this->code = $code;
        $this->show_type = $show_type;
    }

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception  $exception
     * @return void
     */
    public function report()
    {
        //
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request)
    {
        return response()->json([
            'success'      => $this->type == 'SUCCESS',
            'data'         => $this->data,
            'errorCode'    => $this->code,
            'errorMessage' => $this->message,
            'showType'     => $this->show_type
        ]);
    }

}
